//
//  Cookie.m
//  CandyCrushClone
//
//  Created by  Stefan Nestorov on 12/29/14.
//  Copyright (c) 2014 Nestorov Engineering. All rights reserved.
//

#import "RWTCookie.h"
#import "Globals.h"

@implementation RWTCookie  

- (NSString *)spriteName
{
    
    static NSString * const spriteNames[] = {
        @"1set1",
        @"2set1",
        @"3set1",
        @"4set1",
        @"5set1",
        @"6set1",
    };
    
    return spriteNames[self.cookieType - 1];
    
}

- (NSString *)highlightedSpriteName
{
    
    static NSString * const highlightedSpriteNames[] = {
        @"1set1-Highlighted",
        @"2set1-Highlighted",
        @"3set1-Highlighted",
        @"4set1-Highlighted",
        @"5set1-Highlighted",
        @"6set1-Highlighted",
    };
    
    return highlightedSpriteNames[self.cookieType - 1];
    
}

- (NSString *)description
{
    
    return [NSString stringWithFormat:@"type:%ld square:(%ld,%ld)", (long)self.cookieType,
            (long)self.column, (long)self.row];
    
}


- (SFSObject *)asSFSObject
{
    
    SFSObject *cookieSFSObj = [SFSObject new];
    [cookieSFSObj putInt:ROW value:_row];
    [cookieSFSObj putInt:COLUMN value:_column];
    [cookieSFSObj putInt:COOKIE_TYPE value:_cookieType];
    
    return cookieSFSObj;
    
}


+ (instancetype)createCookieFromSFSObect:(SFSObject *)sfsCookie
{
    
    NSInteger col = [sfsCookie getInt:COLUMN];
    NSInteger row = [sfsCookie getInt:ROW];
    NSInteger type = [sfsCookie getInt:COOKIE_TYPE];
    
    RWTCookie *cookie = [[RWTCookie alloc] init];
    cookie.column = col;
    cookie.row = row;
    cookie.cookieType = type;
    
    return cookie;
    
}

- (BOOL)isEqual:(id)obj
{
    if ( obj == self ) return YES;
    if ( obj == nil ) return NO;
    if ( [self class] != [obj class] ) return NO;
    
    RWTCookie *other = (RWTCookie *)obj;
    if ( _column != other.column) return NO;
    if ( _cookieType != other.cookieType) return NO;
    if ( _row != other.row) return NO;
    
    return YES;
    
}

- (NSUInteger)hash
{
    
    const int prime = 31;
    NSInteger result = 1;
    
    result = prime * result + _column;
    result = prime * result + _cookieType;
    result = prime * result + _row;
    
    return result;
    
}


@end
